﻿using Adnc.Application.Shared;
using Adnc.Application.Shared.Dtos;
using Adnc.WebApi.Shared;
using Hangfire;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using WYT.Ord.Application.Contracts.Dtos.ShopCart;
using WYT.Ord.Application.Contracts.Services;

namespace WYT.Ord.WebApi.Controllers
{
    /// <summary>
    /// 购物车
    /// </summary>
    [Route("ord/[Controller]")]
    [ApiController]
    public class ShopCartController : AdncControllerBase
    {
        private readonly IShoppingCartAppService _shoppingCartAppService;
        private readonly IUserContext _userContext;

        public ShopCartController(
            IShoppingCartAppService shoppingCartAppService,
            IUserContext userContext
            )
        {
            _shoppingCartAppService = shoppingCartAppService;
            _userContext = userContext;
        }

        /// <summary>
        /// 添加商品到购物车
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("add")]
        public async Task<WYTActionResult> ProductAdd(ProductAddDto input)
        {
            return Success(await _shoppingCartAppService.AddProduct(_userContext.Id, input));
        }

        /// <summary>
        /// 删除购物车商品
        /// </summary>
        /// <param name="Input"></param>
        /// <returns></returns>
        [HttpPost("delete")]
        public async Task<WYTActionResult> DeleteProduct(SimpleInputDto<long[]> Input)
        {
            return Success(await _shoppingCartAppService.DeleteProduct(_userContext.Id, Input.Value));
        }

        /// <summary>
        /// 修改购物车商品
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("update")]
        public async Task<WYTActionResult> UpdateProduct(ProductModifyDto input)
        {
            return Success(await _shoppingCartAppService.UpdateProduct(_userContext.Id, input));
        }

        /// <summary>
        /// 获取用户购物车商品信息
        /// </summary>
        /// <param name="language"></param>
        /// <returns></returns>
        [HttpGet("list")]
        public async Task<WYTActionResult<List<ProductListDto>>> GetProductList(string language)
        {
            return Success(await _shoppingCartAppService.GetProductList(_userContext.Id, language));
        }
    }
}
